import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

export default new Vuex.Store({
  strict: true,
  plugins: [
    createPersistedState()
  ],
  state: {
    token: null,
    admin: null,
    isAdminLoggedIn: false
  },
  mutations: {
    setToken (state, token) {
      state.token = token
      state.isAdminLoggedIn = !!token
    },
    setAdmin (state, admin) {
      state.admin = admin
    }
  },
  actions: {
    setToken ({ commit }, token) {
      commit('setToken', token)
    },
    setAdmin ({ commit }, Admin) {
      commit('setAdmin', Admin)
    }
  }
})
